let app = getApp()
Component({
    properties: {
          orderId:Number,
          goods_id:Number
      },
      data:{
        activeCommentGood: {},
        activeOrder: {},
        commentImage:[],
        star:0,
        starText: [ "请选择评价", "很不满意", "不满意", "基本满意", "比较满意", "非常满意" ]
      },
    lifetimes: {
        attached: function () {
          var that=this
          this.setData({
            globalColor:app.globalData.globalColor
          })
          wx.request({
              url: app.globalData.siteroot,
              data: { 
                do:'Order_getOrderDetails',
                user_id:wx.getStorageSync('user_id'),
                order_id:that.data.orderId
              },
              success: function(res) {
                  that.setData({
                    activeCommentGood:res.data.data.goods_item
                  })
              }
            })
       }
      },
    methods: {
      write:function(e){
         this.setData({
            content:e.detail.value
         })
      },
      submitcomment:function(){
        var content=this.data.content
        if(typeof(content)=='undefined'||content=='')
        {
          wx.showToast({
            title: '请输入评价内容',
            icon: 'none', 
            duration: 1500 
        })
        }else{
          var that=this
          wx.request({
            url: app.globalData.siteroot,
            data: { 
              do:'Order_orderComment',
              user_id:wx.getStorageSync('user_id'),
              order_id:that.data.orderId,
              goods_id:that.data.goods_id,
              content:content,
              img_group:that.data.commentImage,
              star_num:that.data.star,
              sku_id:0
            },
            success: function(res) {
              wx.showToast({
                title: '发布成功',
                icon: 'success', 
                duration: 1500 
            })
            wx.navigateTo({
              url: '/yb_shopv2/native/all/index?type=mine_order&tab=4'
            })
            }
          })
  
        }
      },
      deleteimg:function(e){
        var index=e.currentTarget.dataset.index
        var array=this.data.commentImage
        array.splice(index, 1);
        this.setData({
          commentImage:array
        })
      },
      upload:function(){
        var that = this;
        wx.showActionSheet({
        itemList: ['从相册中选择', '拍照'],
        success: function (res) {
        if (!res.cancel) {
        if (res.tapIndex == 0) {
               that.chooseWxImageShop('album');
        } else if (res.tapIndex == 1) {
               that.chooseWxImageShop('camera');
            }
          }
         }
        })
      },
      chooseWxImageShop: function (type) {
        var that = this;
        wx.chooseImage({
        sizeType: ['original', 'compressed'],
        sourceType: [type],
        success: function (res) {
        that.data.user_headimg = res.tempFilePaths[0],
        that.upload_file(res.tempFilePaths[0])
           }
         })
        },
        upload_file: function (filePath) {
          var that = this;
          wx.uploadFile({
          url:app.globalData.siteroot+'&do=Index_uploadFile',
          filePath: filePath,
          name: 'file_upload',
          header: {
          'content-type': 'multipart/form-data'
          }, 
          formData: {
          'do':'Index_uploadFile',
          },
          success: function (res) {
          var data=JSON.parse(res.data)
          that.data.commentImage.push(data.info.url)
          that.setData({
             commentImage:that.data.commentImage
           })
          },
          fail: function (res) {}
          })
      },
      updateStarNum:function(e){
        this.setData({
          star:e.detail
        })
      }
    }
});
